﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMSSnew.DATA;


namespace SMSSnew.UI
{
    public partial class vicePrinLeaveHand : System.Web.UI.Page
    {
        LeaveApplicationListDA sendDataToDB;
        static string teacherId, leaveId, userName;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               userName = Session["username"].ToString();
                loadLeavesToGrid();
            }
        }

        protected void loadLeavesToGrid()
        {
            try
            {
                DataTable leaveGrid = new DataTable();
                sendDataToDB = new LeaveApplicationListDA();

                leaveGrid = sendDataToDB.loadLeavesToVPrincipal();
                grdRequestedLeaves.DataSource = leaveGrid;
                grdRequestedLeaves.DataBind();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void grdRequestedLeaves_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            MapDataToControllers(e);
        }

        private void MapDataToControllers(Telerik.Web.UI.GridCommandEventArgs e)
        {
            sendDataToDB = new LeaveApplicationListDA();

            try
            {
                leaveId = e.Item.Cells[3].Text;
                teacherId = e.Item.Cells[4].Text;

                if (e.CommandName == "deleteLeave")
                {
                    //PopUpMessage("Are you sure you want to delete the leave? ");
                  //  sendDataToDB.deleteLeave(teacherId, leaveId);
                    loadLeavesToGrid();
                }

                if (e.CommandName == "changeStatus")
                {
                    pnlGridLeave.Visible = false;
                    pnlChangeStatus.Visible = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void btnCHangeOk_Click(object sender, EventArgs e)
        {
            sendDataToDB = new LeaveApplicationListDA();

            if (rdbListStatus.SelectedValue == "Approve")
            //    sendDataToDB.updateLeave(teacherId, leaveId, 2);
            if (rdbListStatus.SelectedValue == "Reject")
            //    sendDataToDB.updateLeave(teacherId, leaveId, 1);

            loadLeavesToGrid();
            pnlGridLeave.Visible = true;
            pnlChangeStatus.Visible = false;
            rdbListStatus.ClearSelection();
        }

        protected void imgBtnBack_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/UI/Home_V_Principal.aspx");
        }

        


      
        
      

    }
}
